//by chen

$(function(){
//以下用户名验证
	var userName = $("#userName");  
     //页面加载时清空text  
    userName.val("");  
    var userName_span = $("#userName_span");  
    var reg1 = /^[A-Za-z]{1}(\w){4,19}$/; //正则：5-20位字母、数字或下划线组合，首字符必须为字母  
    var userName_span1 = "<font style='color:red'>请输入用户名！</font>";  
    var userName_span2 = "<font style='color:red'>用户名已经存在！</font>";  
    var userName_span3 = "<font style='color:green'>用户名可用！</font>";  
    var userName_span4 = "<font style='color:red'>用户名格式不正确！</font>";  
    userName.change(function() {  
         //当userName文本框中没有数据时，设置文本框的border样式，做出提示  
    	var userNameVal1 = $.trim(userName.val());  
    	var userNameVal2 = userName.val();  
        if(userNameVal1 == ""){  
             userName.addClass("userText");  
             userName_span.html(userName_span1);  
             return false;  
         }else{ 
             userName.removeClass("userText");  
             userName_span.html(""); 
             //alert(userNameVal2)
             if(!reg1.test(userNameVal2)){
                 userName.addClass("userText");  
                 userName_span.html(userName_span4);  
                 return false;  
             }else{  
                 //到服务端判断用户名是否存在  
                 $.post(  
                     "checkUser.action",  
                     {"userName":userNameVal1},  
                     function(result){ 
                    	 //alert(result)
                         if(result){ 
                             userName.removeClass("userText");  
                             userName_span.html(userName_span2);  
                             return false;  
                         }else{  
                             userName.removeClass("userText");  
                             userName_span.html(userName_span3);  
                             return true;  
                         }  
                     },  
                     "json"  
                 );  
             }  
         }  
     });
    //效验密码是否一样
    var password=$("#password");
    var passwordConfirm=$("#passwordConfirm");
    var passwordSpan=$("#password_span");
    var password_span1 = "<font style='color:red'>两次输入不一致！</font>";
    var password_span2 = "<font style='color:green'>输入一致！可用</font>";
    passwordConfirm.blur(function(){
    	if(password.val()!=passwordConfirm.val()){
    		passwordSpan.html(password_span1);
    	}
    	else{
    		passwordSpan.html(password_span2);
    	}
    });